package com.yalantis.ucrop;

import android.app.Activity;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;

import java.io.File;

/**
 * Created by Administrator on 2016/11/24.
 */
public class CropUtils {


    /**
     * 进入裁剪页面
     *
     * @param uri
     * @param activity
     */
    public static void startCropActivity(@NonNull Uri uri, Activity activity, int aspectRatioX, int aspectRatioY) {
        UCrop uCrop = UCrop.of(uri, Uri.fromFile(new File(activity.getCacheDir(), "CropImage.jpg")));

        uCrop = uCrop.withAspectRatio(aspectRatioX, aspectRatioY);
        //初始化UCrop配置
        UCrop.Options options = new UCrop.Options();
        //是否隐藏底部容器，默认显示
        options.setHideBottomControls(true);
        //设置裁剪的图片质量，取值0-100
//        options.setCompressionQuality(100);
        //设置图片压缩最大值
//        options.setMaxBitmapSize(500);
        options.setToolbarColor(ActivityCompat.getColor(activity, R.color.ucrop_color_toolbar));
        //设置状态栏颜色
        options.setStatusBarColor(ActivityCompat.getColor(activity, R.color.ucrop_color_toolbar));
        //UCrop配置
        uCrop.withOptions(options);
        uCrop.start(activity);
    }


}
